package com.mingxi.backend.controller;

import com.mingxi.backend.common.Result;
import com.mingxi.backend.mapper.CourseMapper;
import com.mingxi.backend.pojo.dto.AddCourseDto;
import com.mingxi.backend.pojo.entity.Course;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController()
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseMapper courseMapper;

    @GetMapping
    public Result getCourse() {
        List<Course> courses = courseMapper.get();
        return Result.success(courses);
    }

    @PostMapping
    public Result addCourse(AddCourseDto addCourseDto) {
        courseMapper.addCourse(addCourseDto);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteCourse(Course course) {
       courseMapper.update(course);
       return Result.success();
    }

    @PutMapping
    public Result updateCourse(Course course) {
        courseMapper.update(course);
        return Result.success();
    }
}
